package com.yyf.blogapi.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.yyf.blogapi.mapper.ArticleMapper;
import com.yyf.blogapi.po.Article;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class UpdateViewCountService {

    @Async("taskExecutor")
    public void updateViewCount(ArticleMapper articleMapper, Article article) {
        Article updateViewArticle = new Article();
        updateViewArticle.setViewCounts(article.getViewCounts() + 1);
        /*LambdaUpdateWrapper<Article> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(Article::getId, article.getId());
        updateWrapper.eq(Article::getViewCounts,article.getViewCounts());
        articleMapper.update(updateViewArticle,updateWrapper);*/
        updateViewArticle.setId(article.getId());
        articleMapper.updateById(updateViewArticle);
    }
}
